<% layout( 'layout') -%>

          <h2 class="sub-header">Change Admin Password</h2>

          <form class="form-horizontal" role="form">
                <div class="form-group">
                  <label for="oldPassword"  class="col-sm-2 control-label">Old Password: </label>
                  <div class="col-sm-2">
                    <input type="password" id="oldPassword" class="form-control" required>
                  </div>
                </div>
                <div class="form-group">
                  <label for="password1"  class="col-sm-2 control-label">New Password: </label>
                  <div class="col-sm-2">
                    <input type="password" id="password1" class="form-control" required>
                  </div>
                </div>
                <div class="form-group">
                  <label for="password2"  class="col-sm-2 control-label">Confirm Password: </label>
                  <div class="col-sm-2">
                    <input type="password" id="password2" class="form-control" required>
                  </div>
                </div>
                <div class="form-group">
                  <div class="col-sm-offset-2">
                    <input type="button" id="submit" value="Submit" class="btn btn-md btn-primary">
                  </div>
                </div>
          </form>


<script type="text/javascript">
   $(function () {
      $("#submit").click(function() {
        var oldPassword = $('#oldPassword').val();
        var password1 = $('#password1').val();
        var password2 = $('#password2').val();

        if (password1 == '') {
          alert('Password cannot be empty')
          return;
        }

        if (password1 != password2) {
          alert('Password not consistent')
          return;
        }

        $.ajax({
            type: "POST",
            cache: false,
            url: "/api/user/changepwd",
            data: {
              oldpwd: oldPassword,
              newpwd: password1,
            },
            success: function(msg){
              if (msg.status != 0) {
                alert(msg.error);
                return;
              }

              alert('Change password success');
            }
        });

        return false;
      });
  });
</script>